/**
 * 
 */
package com.aihwcm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aihwcm.entity.Aihdocuments;
import com.aihwcm.entity.AihdocumentsDAO;
import com.aihwcm.entity.Aihrelateddocs;
import com.aihwcm.entity.AihrelateddocsDAO;

/**
 * @author francisli
 *
 */
@Component("RelatedDocManageService")
public class RelatedDocManageServiceImpl implements RelatedDocManageService {

	@Autowired(required = false)
	private AihdocumentsDAO aihdocumentsDAO;
	@Autowired(required = false)
	private AihrelateddocsDAO aihrelateddocsDAO;

	@Override
	public void saveRelatedDoc(Aihrelateddocs relatednews) {

		aihrelateddocsDAO.save(relatednews);

	}

	@Override
	public void delRelatedDoc(int docid) {

		Aihdocuments aihdocuments = aihdocumentsDAO.findById(docid);
		List<Aihrelateddocs> list = aihrelateddocsDAO.findByProperty(
				"aihdocuments", aihdocuments);
		for (Aihrelateddocs relatednews : list) {
			aihrelateddocsDAO.delete(relatednews);
		}

	}

	@Override
	public List<Aihrelateddocs> findByRelatedDocid(int docid) {

		Aihdocuments aihdocuments = aihdocumentsDAO.findById(docid);
		List<Aihrelateddocs> list = aihrelateddocsDAO.findByProperty(
				"aihdocuments", aihdocuments);
		return list;
	}
}
